#include <iostream>
#include <string>

using namespace std;

int n,m;
string s;

void change(int l, int r)
{
    for(int i=l-1;i<r;i++)
    {
        if(s[i]=='(')
            {s[i]=')';}
        else
            {s[i]='(';}
    }
    return;
}

int solve(int l)
{
    int lc = 0;
    int result = 0;

    for(int i=l-1;i<n;i++)
    {
        if(s[i]=='(')
            {lc++;}
        else
        {
            lc--;
            if(lc<0){break;}
        }
        if(lc==0){result=i+1;}
    }
    return result;
}

int main()
{
    cin>>n>>m;
    cin>>s;
    while(m--)
    {
        int type;
        cin>>type;
        if(type==1)
        {
            int l, r;
            cin>>l>>r;
            change(l, r);
        }
        else
        {
            int l;
            cin>>l;
            cout<<solve(l);
        }
    }
    return 0;
}
